<?php
class Core_Business_Trainingcandidate extends Core_Business_Abstract {
	private $_trainingid;
	private $_userid;
	private $_choose;
	
	public function __construct() {
		$this->_choose = 0;
	}
	
	public function getTrainingid() {return $this->_trainingid;}
	public function setTrainingid($value) {$this->_trainingid=$value;}
	
	public function getUserid() {return $this->_userid;}
	public function setUserid($value) {$this->_userid=$value;}
	
	public function getIsSelect() {return $this->_choose;}
	public function setIsSelect($value) {$this->_choose=$value;}
	
	
	public static function getAllCandidate($trainingid) {
		$map = new Core_Data_Mappers_Trainingcandidate();
		$candidates = $map->fetchAll(array("trainingid = ?"=>$trainingid));
		return $candidates;
	}
	public static function isPostulate($training,$userid) {
		$map = new Core_Data_Mappers_Trainingcandidate();
		$postule = new self();
		$postule->Trainingid = $training;
		$postule->Userid = $userid;
		return $map->exists($postule);
	}
	public static function getPostulate($training,$userid) {
		$map = new Core_Data_Mappers_Trainingcandidate();
		$postule = new self();
		$postule->Trainingid = $training;
		$postule->Userid = $userid;
		return $map->find($postule);
	}
	public static function getPostule($training) {
		$map = new Core_Data_Mappers_Trainingcandidate();
		$tr = $map->fetchAll(array("trainingid = ?"=>$training,"choose = 1"));
		return $tr;
	}
	public function save() {
		$map = new Core_Data_Mappers_Trainingcandidate();
		$map->save($this);
	}
}